package com.googlecode.wicketcharts.highcharts.options;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

/**
 * Defines the configuration of the "lang" option. Use
 * {@link #forLocale(Locale)} to create a preconfigured {@link LanguageOptions}
 * object for a specific locale.
 * 
 * @see <a href="http://api.highcharts.com/highcharts#lang">http://api.highcharts.com/highcharts#lang</a>
 * @author Tom Hombergs (tom.hombergs@gmail.com)
 * 
 */
public class LanguageOptions extends JsonObject {

	private static final long serialVersionUID = 1L;

	private String decimalPoint;

	private String downloadPNG;

	private String downloadJPEG;

	private String downloadPDF;

	private String downloadSVG;

	private String exportButtonTitle;

	private String loading;

	private List<String> months;

	private List<String> shortMonths;

	private String printButtonTitle;

	private String resetZoom;

	private String resetZoomTitle;

	private String thousandsSep;

	private List<String> weekdays;

	/**
	 * Returns the {@link LanguageOptions} for the specified locale. If the
	 * locale is not supported, an empty {@link LanguageOptions} object is
	 * returned. Highcharts will then automatically fall back to english.
	 * <p/>
	 * To look up the locale-specific strings, the resource bundle
	 * com/googlecode/wicketcharts/highcharts/options/LanguageOptions
	 * .properties is used. To add your own language, simply copy one of the
	 * existing resource bundles, modify it and then add it in the classpath in
	 * the same package.
	 * <p/>
	 * 
	 * 
	 * @param locale
	 *            the locale for which to create the Language options.
	 * @return the language options in the specified locale.
	 */
	public static LanguageOptions forLocale(Locale locale) {
		try {
			ResourceBundle bundle = ResourceBundle.getBundle(
					LanguageOptions.class.getName(), locale);
			LanguageOptions options = new LanguageOptions();
			options.setDecimalPoint(bundle.getString("decimalPoint"));
			options.setDownloadPNG(bundle.getString("downloadPNG"));
			options.setDownloadJPEG(bundle.getString("downloadJPEG"));
			options.setDownloadPDF(bundle.getString("downloadPDF"));
			options.setDownloadSVG(bundle.getString("downloadSVG"));
			options.setExportButtonTitle(bundle.getString("exportButtonTitle"));
			options.setLoading(bundle.getString("loading"));
			options.setMonths(Arrays.asList(bundle.getString("months").split(
					",")));
			options.setShortMonths(Arrays.asList(bundle
					.getString("shortMonths").split(",")));
			options.setPrintButtonTitle(bundle.getString("printButtonTitle"));
			options.setResetZoom(bundle.getString("resetZoom"));
			options.setResetZoomTitle(bundle.getString("resetZoomTitle"));
			options.setThousandsSep(bundle.getString("thousandsSep"));
			options.setWeekdays(Arrays.asList(bundle.getString("weekdays")
					.split(",")));
			return options;
		} catch (MissingResourceException e) {
			// empty LanguageOptions = english, since this is the default of
			// highcharts
			return new LanguageOptions();
		}
	}

	public String getDecimalPoint() {
		return decimalPoint;
	}

	public void setDecimalPoint(String decimalPoint) {
		this.decimalPoint = decimalPoint;
	}

	public String getDownloadPNG() {
		return downloadPNG;
	}

	public void setDownloadPNG(String downloadPNG) {
		this.downloadPNG = downloadPNG;
	}

	public String getDownloadJPEG() {
		return downloadJPEG;
	}

	public void setDownloadJPEG(String downloadJPEG) {
		this.downloadJPEG = downloadJPEG;
	}

	public String getDownloadPDF() {
		return downloadPDF;
	}

	public void setDownloadPDF(String downloadPDF) {
		this.downloadPDF = downloadPDF;
	}

	public String getDownloadSVG() {
		return downloadSVG;
	}

	public void setDownloadSVG(String downloadSVG) {
		this.downloadSVG = downloadSVG;
	}

	public String getExportButtonTitle() {
		return exportButtonTitle;
	}

	public void setExportButtonTitle(String exportButtonTitle) {
		this.exportButtonTitle = exportButtonTitle;
	}

	public String getLoading() {
		return loading;
	}

	public void setLoading(String loading) {
		this.loading = loading;
	}

	public List<String> getMonths() {
		return months;
	}

	public void setMonths(List<String> months) {
		this.months = months;
	}

	public List<String> getShortMonths() {
		return shortMonths;
	}

	public void setShortMonths(List<String> shortMonths) {
		this.shortMonths = shortMonths;
	}

	public String getPrintButtonTitle() {
		return printButtonTitle;
	}

	public void setPrintButtonTitle(String printButtonTitle) {
		this.printButtonTitle = printButtonTitle;
	}

	public String getResetZoom() {
		return resetZoom;
	}

	public void setResetZoom(String resetZoom) {
		this.resetZoom = resetZoom;
	}

	public String getResetZoomTitle() {
		return resetZoomTitle;
	}

	public void setResetZoomTitle(String resetZoomTitle) {
		this.resetZoomTitle = resetZoomTitle;
	}

	public String getThousandsSep() {
		return thousandsSep;
	}

	public void setThousandsSep(String thousandsSep) {
		this.thousandsSep = thousandsSep;
	}

	public List<String> getWeekdays() {
		return weekdays;
	}

	public void setWeekdays(List<String> weekdays) {
		this.weekdays = weekdays;
	}

}
